Skip to content

feat:support soft delete for join#1199

Closed
YukiMichishita wants to merge 1 commit intogo-gorm:masterfrom
YukiMichishita:soft_delete_for_join
Closed

feat:support soft delete for join#1199
YukiMichishita wants to merge 1 commit intogo-gorm:masterfrom
YukiMichishita:soft_delete_for_join

Conversation

@YukiMichishita
Copy link
Copy Markdown

  • Do only one thing
  • Non breaking API changes
  • Tested

What did this pull request do?

This pull request adds support for handling soft deletes in the target table during JOIN operations.
Close #883.

@qqxhb
Copy link
Copy Markdown
Member

qqxhb commented Mar 2, 2026

Thanks for the PR!

We’re going to close this for now.

Reasoning:

  • Join/LeftJoin/RightJoin in gen are low-level helpers that accept explicit ON conditions. Users can already include soft-delete constraints explicitly when needed (e.g. add joinedTable.DeletedAt.IsNull() / field.NewField(joinedTable.TableName(), "deleted_at").IsNull() as an extra join condition).
  • For relationship-based joins, DO.Joins(relationField) delegates to GORM’s Joins(...), which already applies model query clauses (including soft-delete) for the joined schema.
  • The implementation here tries to infer relationships from d.db.Statement.Schema.Relationships and then rebuild SQL by string-replacing bind variables. That’s quite fragile (aliases, multiple joins, different dialectors/bindvars, statement state) and there are no CI checks/tests on the branch.

If we revisit this in the future, it would likely need a more robust approach plus coverage tests.

@qqxhb
Copy link
Copy Markdown
Member

qqxhb commented Mar 2, 2026

Closing: soft-delete can be handled via explicit join conditions or relationship Joins(); current approach is too fragile.

@qqxhb qqxhb closed this Mar 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

连表的时候右边软删除字段没生效

2 participants